home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
pctchnqs
/
1992
/
number2
/
tvouterr.cpp
< prev
next >
Wrap
Text File
|
1992-02-13
|
3KB
|
126 lines
#include <iostream.h>
#define Uses_otstream
#define Uses_TApplication
#define Uses_TDeskTop
#define Uses_TRect
#define Uses_TTerminal
#define Uses_TWindow
#include <tv.h>
class TOutputWindow : public TWindow
{
TTerminal *_term;
public:
TOutputWindow(TRect bounds, const char *title,
ostream_withassign& ostr, ushort bufsize);
void attach(ostream_withassign& ostr)
{
// Attach TTerminal stream buffer to I/O stream.
ostr = _term;
}
};
class TOutErr : public TApplication
{
ostream_withassign _old_cout;
ostream_withassign _old_cerr;
ostream_withassign _old_clog;
public:
TOutErr(TRect& outbounds, ushort outbufsize, TRect& errbounds,
ushort errbufsize);
~TOutErr();
virtual void run();
};
TOutputWindow::TOutputWindow(TRect bounds, const char *title,
ostream_withassign& ostr, ushort bufsize) :
TWindowInit(&TOutputWindow::initFrame),
TWindow(bounds, title, wnNoNumber)
{
// Terminal view should cover entire window.
bounds = getExtent();
bounds.grow(-1, -1);
// Create terminal view and add to window.
_term = new TTerminal(bounds,
standardScrollBar(sbHorizontal | sbHandleKeyboard),
standardScrollBar(sbVertical | sbHandleKeyboard), bufsize);
insert(_term);
// Create TV output stream.
otstream ot(_term);
ot << "Terminal window \"" << title << "\" created." << endl;
// Copy output stream; normally attach(ostr) would be sufficient.
ostr = ot;
}
TOutErr::TOutErr(TRect& outbounds, ushort outbufsize,
TRect& errbounds, ushort errbufsize) :
TProgInit(&TOutErr::initStatusLine, &TOutErr::initMenuBar,
&TOutErr::initDeskTop)
{
// Save current I/O assignments.
_old_cout = cout;
_old_cerr = cerr;
_old_clog = clog;
TOutputWindow *tow;
// Create standard output window.
tow = new TOutputWindow(outbounds, "Standard Output", cout,
outbufsize);
deskTop->insert(tow);
// Create standard error window and attach to log stream.
tow = new TOutputWindow(errbounds, "Standard Error", cerr,
errbufsize);
tow->attach(clog);
deskTop->insert(tow);
}
TOutErr::~TOutErr()
{
// Restore old I/O assignments.
cout = _old_cout;
cerr = _old_cerr;
clog = _old_clog;
}
void TOutErr::run()
{
cout << "Testing standard output:";
for (int i = 0; i < 10; i++)
cout << ' ' << i;
cout << endl;
cerr << "Testing standard error:";
for (; i < 20; i++)
cerr << ' ' << i;
cerr << endl;
clog << "Testing log:";
for (; i < 30; i++)
clog << ' ' << i;
clog << endl;
TApplication::run();
}
int main()
{
TOutErr outerr(TRect(0, 0, 80, 15), 8192, TRect(0, 15, 80, 23),
2048);
outerr.run();
return (0);
}